package com.ruoyi.animal.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.animal.domain.AnimalInformation;
import com.ruoyi.animal.service.IAnimalInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.animal.domain.HealthCheckup;
import com.ruoyi.animal.service.IHealthCheckupService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 动物健康检测Controller
 * 
 * @author gw
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/checkup")
public class HealthCheckupController extends BaseController
{
    @Autowired
    private IHealthCheckupService healthCheckupService;

    @Autowired
    private IAnimalInformationService animalInformationService;

    /**
     * 查询动物健康检测列表
     */
    @RequiresPermissions("animal:checkup:list")
    @GetMapping("/list")
    public TableDataInfo list(HealthCheckup healthCheckup)
    {
        startPage();
        List<HealthCheckup> list = healthCheckupService.selectHealthCheckupList(healthCheckup);
        for(HealthCheckup healthCheckup1:list){
            AnimalInformation animalInformation = animalInformationService.selectAnimalInformationByAnimalId(healthCheckup1.getAnimalId());
            if(animalInformation!=null) {
                healthCheckup1.setAnimalNumber(animalInformation.getAnimalNumber());
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出动物健康检测列表
     */
    @RequiresPermissions("animal:checkup:export")
    @Log(title = "动物健康检测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HealthCheckup healthCheckup)
    {
        List<HealthCheckup> list = healthCheckupService.selectHealthCheckupList(healthCheckup);
        ExcelUtil<HealthCheckup> util = new ExcelUtil<HealthCheckup>(HealthCheckup.class);
        util.exportExcel(response, list, "动物健康检测数据");
    }

    /**
     * 获取动物健康检测详细信息
     */
    @RequiresPermissions("animal:checkup:query")
    @GetMapping(value = "/{checkupId}")
    public AjaxResult getInfo(@PathVariable("checkupId") Long checkupId)
    {
        return success(healthCheckupService.selectHealthCheckupByCheckupId(checkupId));
    }

    /**
     * 新增动物健康检测
     */
    @RequiresPermissions("animal:checkup:add")
    @Log(title = "动物健康检测", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthCheckup healthCheckup)
    {
        return toAjax(healthCheckupService.insertHealthCheckup(healthCheckup));
    }

    /**
     * 修改动物健康检测
     */
    @RequiresPermissions("animal:checkup:edit")
    @Log(title = "动物健康检测", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthCheckup healthCheckup)
    {
        return toAjax(healthCheckupService.updateHealthCheckup(healthCheckup));
    }

    /**
     * 删除动物健康检测
     */
    @RequiresPermissions("animal:checkup:remove")
    @Log(title = "动物健康检测", businessType = BusinessType.DELETE)
	@DeleteMapping("/{checkupIds}")
    public AjaxResult remove(@PathVariable Long[] checkupIds)
    {
        return toAjax(healthCheckupService.deleteHealthCheckupByCheckupIds(checkupIds));
    }
}
